<template>
  <div class="password">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="原密码">
        <el-input v-model="form.bepass"></el-input>
      </el-form-item>

      <el-form-item label="新密码">
        <el-input v-model="form.newpass"></el-input>
      </el-form-item>

      <el-form-item label="重输">
        <el-input v-model="form.repass"></el-input>
      </el-form-item>

      <el-form-item class="c">
        <el-button type="primary" @click="onSubmit">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("salesmans");
export default {
  data() {
    return {
      form: {
         bepass:'',
         newpass:'',
         repass:''

      },
    };
  },
  methods:{
       ...mapActions(["getSalesmansDataById",'modifySalesmansById']),
     async onSubmit()
      {
        
          if(this.form.newpass!=this.form.repass)
          {
              alert('新密码重输不正确!请确认无误后再提交');
          }
          else
          {
             const trans=JSON.parse(localStorage.loginUser);
             const re= await this.getSalesmansDataById({_id:trans._id});
            
             if(re.password!=this.form.bepass)
             {
                 alert('原密码输入不正确！');
             }
             else
             {
                 this.modifySalesmansById({
                     _id:re._id,
                     Data:{
                         password:this.form.repass,
                     }
                 })
             }
          }
      }
  }
};
</script>

<style>
.password {
    position: relative;
}
.password .el-form{
    margin: 100px auto;
    padding-left: 300px;

}
.password .c{
    position: absolute;
    top:220px;
    left: 410px;
}
.password .el-input{
    width:350px !important;
}
</style>